﻿using Project_veilingsite.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Project_veilingsite.Controllers
{
    public class LoginController : Controller
    {
        [HttpGet]
        public ActionResult Loginform()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Loginform(LoginModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    TempData["notice"] = "username=" + model.UserName + " password=" + model.Password;
                    return RedirectToAction("Index", "Home");
                }
            }
            catch (Exception e)
            {
                //Server.MapPath("~") = de root-map van het project
                string pad = Server.MapPath("~") + "/LoggingTracing/tracingLogging.txt";
                if (!System.IO.File.Exists(pad))
                {
                    System.IO.File.Create(pad);
                }

                using (StreamWriter swTracing = System.IO.File.AppendText(pad))
                {
                    swTracing.Write("\n\nDatum/Tijd: " + DateTime.Now + "\nException: " + e.StackTrace);
                }
            }
            return View();
        }
    }
}